<template>
  <div>
    <div class="search">
      <!-- 搜索 -->
      <el-input size="mini" style="width:180px" placeholder="账号" prefix-icon="el-icon-search" v-model="keyword"></el-input>
      <!-- 登录时间 -->
      <el-date-picker
      size="mini"
        class="datay"
        v-model="startTime"
        type="date"
        placeholder="开始时间"
        value-format="yyyy-MM-dd"
        @change="getSTime"
      ></el-date-picker>
      <span style="padding: 0 20px;">至</span>
      <el-date-picker
      size="mini"
        v-model="endTime"
        type="date"
        placeholder="结束时间"
        value-format="yyyy-MM-dd"
        @change="getSTime"
      ></el-date-picker>
      <!-- 确定 -->
      <el-button size="mini" class="datay" type="primary" @click="fetchData">确定</el-button>
      <!-- 取消 -->
      <el-button size="mini" class="datay" @click="assert">重置</el-button>
    </div>

    <!-- 列表 -->
    <el-table size="mini" class="list" :data="tableData" border style="width: 100%" :header-cell-style="{background:'#ccc'}">
      <el-table-column prop="userTypeName" label="账号"></el-table-column>
      <el-table-column prop="ipAddress" label="IP地址"></el-table-column>
      <el-table-column prop="ip" label="IP归属"></el-table-column>
      <el-table-column prop="createTime" label="登录时间"></el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination size="mini"
      class="pageNumage"
      @current-change="handleCurrentChange"
      background
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import { getList } from "@/api/table";
import { Loginlog } from "@/api/user";
import qs from "qs";
export default {
  data() {
    return {
      dataTime: "",
      keyword: "", //搜索
      pageNum:1,
      total: 0,
      tableData: [],
      startTime: "", //开始时间
      endTime: "" //结束时间
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    //   分页
    handleCurrentChange(val) {
      this.pageNum = val;
      this.fetchData();
    },
    // 时间
    getSTime(val) {
      this.dataTime = val;
      console.log(this.dataTime, "日期");
    },
    // 取消
    assert(){
        this.keyword = "",
        this.startTime = "",
        this.endTime = ""
    },
    // 接口数据
    fetchData() {
      let data = qs.stringify({
        pageNum: this.pageNum,
        pageSize: 10,
        keyword: this.keyword,
        startTime: this.startTime,
        endTime: this.endTime
      });
      Loginlog(data).then(res => {
        console.log(res.data, 888);
        if (res.data.code == 200) {
          this.tableData = res.data.data;
          this.total = res.data.count;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.search {
  padding: 0 20px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  .datay {
    margin-left: 20px !important;
  }
}
// 列表
.list {
  margin-left: 20px;
  margin-top: 20px;
}
// 分页
.pageNumage {
  float: right;
  margin-top: 20px;
}
</style>
